<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form id="buscar_form" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('config.xhtml')}" value="Configurações" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexLancamento.xhtml')}" value="Lançamentos" update="@form" immediate="true"/> >
                    <p:commandLink  value="Visualizar Lançamento" update="@form" immediate="true"/>
                </div>
                <p:panel header="Lançamentos">
                    <p:messages id="msg"/>

                    <h:panelGrid columns="2" id="panelGridEscolha" columnClasses="textAlignRight">

                        <h:outputLabel value="Prestador:" style="font-weight: bold"/>
                        <h:outputLabel value="#{managerVisaoLancamento.lancamento.prestador.nome}" />

                        <h:outputLabel value="Data :" style="font-weight: bold;text-align: left"/>
                        <h:outputLabel value="#{managerVisaoLancamento.lancamento.dataLanc}" >
                        <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputLabel>
                   
                    </h:panelGrid> 

                    <br/>

                    <h:panelGrid columns="2" id="details" styleClass="detailsTables">
                        <p:column >
                            <p:dataTable id="protocoloTable" var="protocolo" value="#{managerVisaoLancamento.lancamento.protocolos}" 
                                         paginator="true" rows="5"
                                         paginatorPosition="bottom"
                                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                         rowsPerPageTemplate="5,10,15"
                                         emptyMessage="Nenhum Registro Encontrado">    

                                <f:facet name="header">  
                                    Crédito
                                </f:facet>
                                 <p:column style="width:40px;text-align: center">  
                                    <p:commandButton icon="ui-icon-search" oncomplete="dlgProtocolo.show();" update=":buscar_form:dlgProtocolo">
                                        <f:setPropertyActionListener target="#{managerVisaoLancamento.protocolo}" value="#{protocolo}" />
                                    </p:commandButton>
                                </p:column>
                                
                                <p:column  style="width:40px; text-align: center">  
                                    <f:facet name="header" >   
                                        Código
                                    </f:facet>  
                                    <h:outputText value="#{protocolo.id}" style="font-weight: bold;"  />  
                                </p:column>


                                <p:column  style="width:100px;">  
                                    <f:facet name="header" >   
                                        Cartório
                                    </f:facet>  
                                    <h:outputText value="#{protocolo.valorTotalCartorio}" style="font-weight: bold;" >  
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </h:outputText>
                                </p:column>

                                <p:column  style="width:100px;">  
                                    <f:facet name="header" >   
                                        Fermojupi
                                    </f:facet>  
                                    <h:outputText value="#{protocolo.valorTotalFermojupi}" style="font-weight: bold;">  
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </h:outputText>
                                </p:column>

                                

                            </p:dataTable> 
                            
                            <h:panelGrid columns="2" styleClass="maisDetalhes">
                                <h:outputLabel value="Valor cartório:" />
                                <p:inputText value="#{managerVisaoLancamento.totalCartorio}" readonly="true">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                                <h:outputLabel value="Valor Fermojupi:" />
                                <p:inputText value="#{managerVisaoLancamento.totalFermojupi}" readonly="true" >
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                                <h:outputLabel value="Total :" />
                                <p:inputText value="#{managerVisaoLancamento.valorTotalProtocolo}" readonly="true">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                            </h:panelGrid>
                        </p:column> 

                        <p:column>

                            <p:dataTable id="pagamentosTable" var="pagamento" value="#{managerVisaoLancamento.lancamento.pagamentos}" 
                                         paginator="true" rows="5"
                                         paginatorPosition="bottom"
                                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                         rowsPerPageTemplate="5,10,15"
                                         emptyMessage="Nenhum Registro Encontrado">    

                                <f:facet name="header">  
                                    Débito
                                </f:facet>
                                
                                <p:column  style="width:20px;text-align: center">  
                                    <p:commandButton icon="ui-icon-search" oncomplete="dlgPagamento.show();" update=":buscar_form:dlgPagamento">
                                        <f:setPropertyActionListener target="#{managerVisaoLancamento.pagamento}" value="#{pagamento}" />
                                    </p:commandButton>

                                </p:column>

                                <p:column  style="width:40px; text-align: center">  
                                    <f:facet name="header" >   
                                        Código
                                    </f:facet>  
                                    <h:outputText value="#{pagamento.id}" style="font-weight: bold;"  />  
                                </p:column>

                                <p:column  style="width:150px;">  
                                    <f:facet name="header" >   
                                        Titulo
                                    </f:facet>  
                                    <h:outputText value="#{pagamento.titulo}" style="font-weight: bold;"  />  
                                </p:column>

                                <p:column  style="width:50px;">  
                                    <f:facet name="header" >   
                                        Valor
                                    </f:facet>  
                                    <h:outputText value="#{pagamento.valor}" style="font-weight: bold;"   >
                                        <f:convertNumber pattern="#,###,##0.00"/>
                                    </h:outputText>  
                                </p:column>

                                

                            </p:dataTable> 
                            <h:panelGrid columns="2" styleClass="maisDetalhes">
                                <h:outputLabel value="Total :" />
                                <p:inputText value="#{managerVisaoLancamento.valorTotalPagamento}" readonly="true">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                            </h:panelGrid>
                            '    </p:column>
                    </h:panelGrid>

                    <p:panel header="Resumo">
                        <h:panelGrid columns="2" style="width: 100%"  styleClass="detailsTables" id="detailsTables">
                        <p:column>
                            <h:outputLabel value="#{managerVisaoLancamento.lancamento.dataLanc}" style="font-weight: bold">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputLabel>
                            <div class="ui-datatable ui-widget">
                            <table role="grid">
                                <thead>
                                     <tr role="row">
                                        <th class="ui-state-default" role="columnheader">
                                            <div class="ui-dt-c">
                                                <span> Protocolos</span>
                                            </div>
                                        </th>
                                        <th class="ui-state-default" role="columnheader">
                                            <div class="ui-dt-c">
                                                <span>Pagamentos</span>
                                            </div>
                                        </th>
                                        <th class="ui-state-default" role="columnheader" >
                                            <div class="ui-dt-c">
                                                <span>Selos</span>
                                            </div>
                                        </th>
                                     </tr>
                                   </thead>
                                
                                    <tbody class="ui-datatable-data ui-widget-content">
                                        <tr data-ri="0" class="ui-widget-content ui-datatable-even" role="row">
                                            <td role="gridcell">
                                                <div class="ui-dt-c"><span style="font-weight: bold;">#{managerVisaoLancamento.qtdeProtocolos}</span></div>
                                            </td>
                                            <td role="gridcell" >
                                                <div class="ui-dt-c"><span style="font-weight: bold;">#{managerVisaoLancamento.qtdePagamentos}</span></div>
                                            </td>
                                            <td role="gridcell" style="width:100px;">
                                                <div class="ui-dt-c"><span style="font-weight: bold;">#{managerVisaoLancamento.qtdeSelos}</span></div>
                                            </td>
                                        </tr>
                                    </tbody>
                            </table>
                            </div>
                       
                        </p:column>
                            
                            <p:column>
                                <h:panelGrid columns="2" styleClass="maisDetalhes">
                                    <h:outputLabel value="Crédito : " />
                                    <p:inputText value="#{managerVisaoLancamento.totalCredito}" readonly="true" >
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                                    <h:outputLabel value="Débito: " />
                                    <p:inputText value="#{managerVisaoLancamento.totalDebito}" readonly="true" >
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                                    <h:outputLabel value="À receber : " />
                                    <p:inputText value="#{managerVisaoLancamento.totalReceber}" readonly="true" >
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                                    <h:outputLabel value="Receita : " />
                                    <p:inputText value="#{managerVisaoLancamento.totalReceita}" readonly="true" >
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                                </h:panelGrid>
                                    
                            </p:column>
                            
                    </h:panelGrid>
                    </p:panel>
                    
                    <f:facet name="footer" >
                        <center>
                            <p:commandButton value="Voltar" icon="ui-icon-arrowreturnthick-1-w" actionListener="#{managerLancamento.redirect('indexLancamento.xhtml')}" immediate="true"/>
                        </center>
                    </f:facet>
                    
                    <p:dialog modal="true" id="dlgProtocolo" widgetVar="dlgProtocolo" dynamic="true" header="Protocolo">
                        <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="columnLabel,columnData"> 
                            <h:outputLabel value="Id : "/>
                            <h:outputText value="#{managerVisaoLancamento.protocolo.id}" />
                            <h:outputLabel value="Data : "/>
                            <h:outputText value="#{managerVisaoLancamento.protocolo.dataCad}">
                                 <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            <h:outputLabel value="Cliente : "/>
                            <h:outputText value="#{managerVisaoLancamento.protocolo.cliente.nome}" />
                            <h:outputLabel value="Forma de pagamento: "/>
                            <h:outputText value="#{managerVisaoLancamento.protocolo.formasPagamento.nome}" />
                            
                            
                             <h:outputLabel value="Serviços do Protocolo" style="font-weight: bold;"/>
                             <table style="width:100%">
                                    <tbody style="background-color: #5277A9; color: #ffffff; ">
                                     <td style="font-weight: bold; text-align: center;">
                                         Ato Item
                                    </td>
                                     <td style="font-weight: bold; text-align: center;">
                                         Cartório
                                     </td>
                                     <td style="font-weight: bold; text-align: center;">
                                         Fermojupi
                                    </td>
                                     <td style="font-weight: bold; text-align: center;" >
                                         Valor
                                    </td>
                                     
                                 </tbody>
                                <ui:repeat value="#{managerVisaoLancamento.protocolo.servicoProtocolos}" var="servico">
                                <tr>
                                    <td style="text-align: center;">
                                        <h:outputLabel value="#{servico.atoItem.codigo}" /> - 
                                        <h:outputLabel value="#{servico.atoItem.descricao}" /></td>
                                    <td style="text-align: center;"><h:outputLabel value="#{servico.valorCartorio}" /></td>
                                    <td style="text-align: center;" ><h:outputLabel value="#{servico.valorFermojupi}" /></td>
                                    <td style="text-align: center;"><h:outputLabel value="#{servico.valor}" /></td>
                                     </tr>
                                </ui:repeat>
                           
                             </table>
                            
                            
                        </h:panelGrid>
                    </p:dialog>
                    
                    
                    <p:dialog modal="true" id="dlgPagamento" widgetVar="dlgPagamento" dynamic="true" header="Pagamento">
                        <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="columnLabel,columnData"> 
                            <h:outputLabel value="Id : "/>
                            <h:outputText value="#{managerVisaoLancamento.pagamento.id}" />
                            <h:outputLabel value="Data : "/>
                            <h:outputText value="#{managerVisaoLancamento.pagamento.dataPag}">
                                 <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                            <h:outputLabel value="Título : "/>
                            <h:outputText value="#{managerVisaoLancamento.pagamento.titulo}" />
                            <h:outputLabel value="Interessado : "/>
                            <h:outputText value="#{managerVisaoLancamento.pagamento.interessado}" />
                            <h:outputLabel value="Descrição : "/>
                            <h:outputText value="#{managerVisaoLancamento.pagamento.descricao}" />
                            
                            
                        </h:panelGrid>
                    </p:dialog>
                    
                    
                    <br/>
                </p:panel>
               
                
                <br/>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
